package com.wdb007.venus.wss.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wdb007.venus.wss.channelgroup.BookCaseChannelGroups;
import com.wdb007.venus.wss.service.WebSocketServerService;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelHandler.Sharable;

@Service("wsBookCaseShutdownService")
@Sharable
@Scope("prototype")
public class WsBookCaseShutdownService implements WebSocketServerService{

	private static Logger logger = LoggerFactory.getLogger(WsBookCaseShutdownService.class);
	
	@Override
	public String doService(ChannelHandlerContext ctx, String request) throws Exception {
		JSONObject jsonObj = JSON.parseObject(request);
		logger.info("wsBookCaseRestartService receive Message: {}", request);
		String bookCaseId = jsonObj.getString("bookCaseId");
		jsonObj.remove("bookCaseId");
		logger.info("debug {} : 给机柜[{}],下发策略[{}]",jsonObj.getString("action"), bookCaseId, jsonObj.toJSONString());
		BookCaseChannelGroups.broadcast(bookCaseId, jsonObj.toJSONString());
		return null;
	}

}
